package com.spring.service.impl;

import com.github.benmanes.caffeine.cache.Cache;
import com.spring.dao.TagDao;
import com.spring.pojo.Tag;
import com.spring.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagServiceImpl implements TagService {
    @Autowired
    private TagDao tagDao;
    @Autowired
    private Cache<String,Object> caffeineCache;
    @Override
    public List<Tag> list() {
        List<Tag> list=(List<Tag>)caffeineCache.asMap().get("tagList");
        if(list==null){
             list = tagDao.list();
             caffeineCache.put("tagList", list);
        }
        return list;
    }
}
